Page({
  data: {
    dialogVisible: false,
    homeList:[],
    isShow:false
  },
 onShow(){
  this.getHomeList()
 },
 async getHomeList(){
  const {code ,data:homeList} = await wx.http.get('/room')
  // console.log(homeList);
  if(code!==10000) return wx.utils.toast('失败')
  this.setData({
    homeList,
    isShow:homeList.length===0
  })
 },
  swipeClose(ev) {
    const { position, instance } = ev.detail
    if (position === 'right') {
      // 显示 Dialog 对话框
      this.setData({
        dialogVisible: true,
      })
      // console.log(ev.mark.id);
      this.id = ev.mark.id
      // swiper-cell 滑块关闭
      instance.close()
    }
  },
//点击弹框事件
dialogClose(ev){
  // console.log(ev);
  if(ev.detail === "confirm") this.delHome()
  // console.log(1);
},
//删除数据的函数
async delHome(){
  if(!this.id) return wx.utils.toast('没有id')
  const {code} = await wx.http.delete('/room/'+this.id)
  // console.log(code);
  if(code!==10000) return wx.utils.toast('删除失败')
  this.getHomeList()
  
},
  goDetail(ev) {
    wx.navigateTo({
      url: '/house_pkg/pages/detail/index?id='+ev.mark.id,
    })
  },

  addHouse() {
    wx.navigateTo({
      url: '/house_pkg/pages/locate/index',
    })
  },
})
